//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Text;
using System.Windows.Data;
using OpenLS.Drawing;

namespace OpenLS.Spreadsheet.UI
{
    class TextParagraphConverter: IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            RichTextParagraph p = value as RichTextParagraph;
            if (p == null)
                return null;
            StringBuilder result = new StringBuilder();
            foreach (RichTextRun run in p.Runs)
            {
                result.Append(run.Text);
            }
            return result.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string s = value as string;
            if (s == null)
                return null;
            return new RichTextParagraph(s);
        }

        #endregion
    }
}
